[PATCH 10/11] apparmor: fix race on rawdata dereference
authorJohn Johansen <john.johansen@canonical.com>
Tue, 24 Feb 2026 18:20:02 +0000 (10:20 -0800)
committerSalvatore Bonaccorso <carnil@debian.org>
Thu, 12 Mar 2026 12:28:10 +0000 (13:28 +0100)
commitff20961f3b3a75d990c2a69d5c8ff673df58d8f1
tree14b8cbdd9fb2e741d0bbcdffb7f1470e4ad0bf60
parentbbc258a874b799204c4e7ad00e33fca1c455b4fe
[PATCH 10/11] apparmor: fix race on rawdata dereference

There is a race condition that leads to a use-after-free situation:
because the rawdata inodes are not refcounted, an attacker can start
open()ing one of the rawdata files, and at the same time remove the
last reference to this rawdata (by removing the corresponding profile,
for example), which frees its struct aa_loaddata; as a result, when
seq_rawdata_open() is reached, i_private is a dangling pointer and
freed memory is accessed.

The rawdata inodes weren't refcounted to avoid a circular refcount and
were supposed to be held by the profile rawdata reference.  However
during profile removal there is a window where the vfs and profile
destruction race, resulting in the use after free.

Fix this by moving to a double refcount scheme. Where the profile
refcount on rawdata is used to break the circular dependency. Allowing
for freeing of the rawdata once all inode references to the rawdata
are put.

Fixes: 5d5182cae401 ("apparmor: move to per loaddata files, instead of replicating in profiles")
Reported-by: Qualys Security Advisory <qsa@qualys.com>
Reviewed-by: Georgia Garcia <georgia.garcia@canonical.com>
Reviewed-by: Maxime Bélair <maxime.belair@canonical.com>
Reviewed-by: Cengiz Can <cengiz.can@canonical.com>
Tested-by: Salvatore Bonaccorso <carnil@debian.org>
Signed-off-by: John Johansen <john.johansen@canonical.com>
Gbp-Pq: Topic bugfix/all/qsa-2026-apparmor
Gbp-Pq: Name 0010-apparmor-fix-race-on-rawdata-dereference.patch
security/apparmor/apparmorfs.c
security/apparmor/include/policy_unpack.h
security/apparmor/policy.c
security/apparmor/policy_unpack.c